#include <iostream>
#include <vector>
using namespace std;

int findMinStep(int n) {
    int a = 0;
    int b = 1;
    int c = 1;
    while (n > c)
    {
        a = b;
        b = c;
        c = a + b;
    }

    return c - n > n - b ? n - b : c - n;
}

int main() {
    int n;
    cin >> n;
    int step = findMinStep(n);
    cout << step << endl;

    return 0;
}